//
//  ChorusTableView.m
//  CCBbelefitLife
//
//  Created by 小晓 on 16/1/10.
//  Copyright © 2016年 liurg. All rights reserved.
//

#import "ChorusTableView.h"
#import "MusicChorusTableViewCell.h"

@implementation ChorusTableView
{
    NSMutableArray *dataArray;
}
-(id)initWithFrame:(CGRect)frame dataArray:(NSMutableArray *)dataArr
{
    self = [super initWithFrame:frame];
    if (self)
    {
        self.separatorStyle = UITableViewCellSeparatorStyleNone;
        self.allowsSelection = NO;
        self.delegate = self;
        self.dataSource = self;
    }
    return self;
}

#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return dataArray.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MusicChorusTableViewCell"];
    if ( !cell ) {
        cell = [[MusicChorusTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"MusicChorusTableViewCell"];
    }
    id dataDict = [dataArray objectAtIndex:indexPath.row];
    if(dataDict && [dataDict isKindOfClass:[NSDictionary class]]){
        [(MusicChorusTableViewCell *)cell updataCellViewWithHeadData:dataDict
         superViewCtr:self];
    }
    return cell;
}

#pragma mark - Table view delegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    CGFloat contentWidth = self.frame.size.width;
    // 用何種字體進行顯示
    UIFont *font = [UIFont systemFontOfSize:13];
    
    // 該行要顯示的內容
    NSString *content = [[dataArray objectAtIndex:indexPath.row]objectForKey:@"title"];
    // 計算出顯示完內容需要的最小尺寸
    CGSize size = [content sizeWithFont:font constrainedToSize:CGSizeMake(contentWidth, 1000) lineBreakMode:UILineBreakModeCharacterWrap];
    NSLog(@"size%f",size.height);
    
    return 90+size.height;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 30.0;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 30)];
    headerView.backgroundColor = [UIColor whiteColor];
    UIView * fristView = [[UIView alloc]initWithFrame:CGRectMake(15, 7.5, 3, 15)];
    fristView.backgroundColor = [UIColor orangeColor];
    [headerView addSubview:fristView];
    UILabel * titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(23, 5, 100, 20)];
    titleLabel.text = @"最热合唱";
    titleLabel.textColor = [UIColor orangeColor];
    titleLabel.font = [UIFont systemFontOfSize:16];
    titleLabel.textAlignment = NSTextAlignmentLeft;
    [headerView addSubview:titleLabel];
    return headerView;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
}

@end
